package com.example.yunbiji0314.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger的配置类
 *
 */
@Configuration
//配置开启Swagger和Knife4j的功能 的注解
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {
    /**
     * 生成一个文档对象
     */
    @Bean
    public Docket createRestApi() {
        // 文档类型
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // controller所在的包 扫描@Controller @RestController
                .apis(RequestHandlerSelectors.basePackage("com.example.yunbiji0314.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("云笔记项目")
                .version("1.0")
                .description("文章表的增删改查")
                .build();
    }

}
